<?php
session_start();
ob_start("ob_gzhandler");
require_once '../models/Users.php';

	if(isset($_POST["email"])){
		$_msg="";
		$check=true;
		$email=$_POST["email"];
		$password=$_POST["password"];
		$encryptpassword=Users::encryptpassword($password);
		$row=Users::checkUserLogin($email,$encryptpassword);
		$_SESSION["session_user_id_admin"]=$row['userID'];
		$_SESSION["session_user_email_admin"]=$email;
		$_SESSION["session_user_status_admin"]=$row['status'];
		$session_user_status=$row['status'];
		$_SESSION["session_user_password_admin"]=$encryptpassword;
		
		$session_user_id=$row['userID'];

		if($session_user_id>0 ){
			if($session_user_status==USER_VALUE_ACTIVE){
			header("location: index.php");
			}
			else{
				$_msg.="Tài khoản của bạn chưa được kích hoạt!";
				$check=false;
			}
		}
		else{
		$_msg.="Đăng nhập thất bại!";
		$check=false;
		}

	}

?>


<html dir="ltr" lang="en"><head>
<meta charset="UTF-8">
<title>Administration</title>
<link rel="stylesheet" type="text/css" href="../css/admin.css">
<?php include '../views/_meta.php';?>
</head>
<body>
<div id="container_lg">
<div id="header_lg">
  <div class="div1">
    <div class="div2"><img src="../images/Image-login/logo.png" title="Administration"></div>
      </div>
  </div>
<div id="content_lg">
  <div class="box_lg" style="width: 400px; min-height: 300px; margin-top: 40px; margin-left: auto; margin-right: auto;">
    <div class="heading_lg">
      <h1><img src="../images/Image-login/lockscreen.png" alt=""> Please enter your login details.</h1>
    </div>
    <div class="content_lg" style="min-height: 150px; overflow: hidden;">
                  <form action="" method="post" enctype="multipart/form-data" id="form">
        <table style="width: 100%;">
          <tbody><tr>
            <td style="text-align: center;" rowspan="4"><img src="../images/Image-login/login.png" alt="Please enter your login details."></td>
          </tr>
          <tr>
            <td>Username:<br>
              <input type="text" name="email" value="" style="margin-top: 4px;">
              <br>
              <br>
              Password:<br>
              <input type="password" name="password" value="" style="margin-top: 4px;">
              <br>
              <a  href="">Forgotten Password ?</a></td>
          </tr>
          <tr>
            <td>&nbsp;
			<?php if(isset($_POST['btn_submit'])){
			if($check==false)
			echo "<span class='error'>".$_msg."</span>";
		}?></td>
          </tr>
          <tr>
            <td style="text-align: right;"><input type="submit" class="btn_submit" name="btn_submit" value="Login"></td>
          </tr>
		  <tr>
		  <td></td>
		  </tr>
        </tbody></table>
              </form>
    </div>
  </div>
</div>
</div>
<div id="footer_lg"><a href="">Shopmobile</a>@ 2013-2015 All Rights Reserved.<br>Version 1.5.4</div>
</body></html>